package cn.kgc.airvue.controller;

import cn.kgc.airvue.pojo.Airqualityindex;
import cn.kgc.airvue.pojo.ResultEntity;
import cn.kgc.airvue.service.AirQualitService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class AirController {

    @Resource
    AirQualitService airQualitService;
    @RequestMapping("/seleAir")
    public ResultEntity<PageInfo<Airqualityindex>> seleAir(@RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
                                                           @RequestParam(value = "districtid",required = false,defaultValue = "0")Integer districtid){
        PageInfo<Airqualityindex> sele = airQualitService.sele(pageNum, districtid);
    return ResultEntity.successWithoutData(sele);
    }

    @RequestMapping("/addAir")
    public ResultEntity<String> addAir(@RequestBody Airqualityindex airqualityindex){

//    try {
        Integer add = airQualitService.add(airqualityindex);
        return ResultEntity.successWithoutData(add+"");
//    }catch (Exception ex){
//        return ResultEntity.failed(ex.getMessage());
//    }
    }

}
